package com.easymall.service.impl;

import com.easymall.dao.UserDao;
import com.easymall.domain.User;
import com.easymall.service.UserService;
import com.easymall.util.BaseFactory;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {

    private UserDao userDao;

    @Override
    public void init() throws Exception {
        userDao = BaseFactory.getFactory().getInstance(UserDao.class);
    }

    @Override
    public boolean hasUsername(String username) throws SQLException {
        User user = userDao.getUserByUsername(username);
        return null != user;
    }

    @Override
    public User login(String username, String password) throws SQLException {
        return userDao.getUserByUsernameAndPassword(username, password);
    }

    @Override
    public boolean register(User user) throws SQLException {
        return userDao.saveUser(user);
    }

    @Override
    public User getUserById(int id) throws SQLException {
        return userDao.getUserById(id);
    }
}
